<h1>slots </h1>

<ul>
<li> <a href="#1">About</a>
<ul>
<li> <a href="#2">Sample</a>
<li> <a href="#3">About Plugins</a>
</ul>
<li> <a href="#4">Code</a>
<ul>
<li> <a href="#5">Uses</a>
<li> <a href="#6">Example</a>
<li> <a href="#7">Assumed Functions</a>
<li> <a href="#8">Main</a>
<li> <a href="#9">Workers</a>
</ul>
<li> <a href="#10">Author</a>
</ul>

<a name="1"></a><h2>About</h2>
<p>
<em>Slots</em> is  simple macro langauage- no recursive macros, no macro arguments.
It processes two files: 
</p>
<ul>
<li> A <em>slots</em> file that defines a set of name/value pairs.
<li> A <em>frame</em> file with a set of names slots. 
</ul>
<p>
At runtime, the slot values replace the slot names in the <em>frame</em> file or
from a set of plugins. 
</p>
<a name="2"></a><h3>Sample</h3>
<p>
Here is a slots file. Note how the fields are seperated by back ticks:
</p>
<pre>
  &#96;&#96;name&#96;&#96;   Tim Menzies
  &#96;&#96;office&#96;&#96; 841a
  &#96;&#96;phone&#96;&#96;  28361
</pre>
<p>
And here is a frame file
</p>
<pre>
   Dear &#96;&#96;name&#96;&#96;,
 
   When the pizza arrives, I will call you on &#96;&#96;phone&#96;&#96; and send
   it around to &#96;&#96;office&#96;&#96;.  
  
   Bon Appetit!


   p.s. Fyi: here are the latest updates to our menu: &#96;&#96;rss;tinyurl/pizza.rss;5&#96;&#96;
</pre>
<a name="3"></a><h3>About Plugins</h3>
<p>
Note that the last slot in the frame contains the <em>";"</em> plug-in character. This
slot will be filled in by passing the slot label to the <em>slotsPlugIns</em> function.
</p>
<a name="4"></a><h2>Code</h2>

<a name="5"></a><h3>Uses</h3>
<p>
<a href="?trim">trim</a> <a href="?math">math</a> 
</p>
<a name="6"></a><h3>Example</h3>

<ul>
<li> <a href="?slotsDemo">?slotsDemo</a> is a  simple demo program for this code.
</ul>

<a name="7"></a><h3>Assumed Functions</h3>
<p>
This code assumes that <em>slotsPlugIns</em> has been defined.
</p>
<p>
The <em>slotsPlugIns</em> function accepts two arguments:
</p>
<ol>
<li> For the slots string;
<li> For the set name name/value pairs that define the slots.
</ol>
<p>
<em>Slots</em> prints whatever that function returns. That is,
the above string gets replaced by:
</p>
<pre>
  print slotsPlugIns("rss;tinyurl/pizza.rss;5",values)
</pre>
<a name="8"></a><h3>Main</h3>
<pre>
 function slots(slotsFile,frameFile,      values,sep) {
     sep="`""`"
     loadSlots(slotsFile,sep,values)   
     fillFrame(frameFile,sep,values)
 }
</pre>
<a name="9"></a><h3>Workers</h3>
<pre>
 function loadSlots(slots,sep,values,   n,i,all) {
     n=slurp(slots,all,sep)
     for(i=2; i&lt;=n; i += 2) 
	 values[trim(all[i])] = trim(all[i+1]);
 }
 function fillFrame(frame,sep,values,   all,n,i) {
     print fillFrame2String(frame,sep,values)
 }
 function fillFrame2String(frame,sep,values,   all,n,i,str) {
     n=slurp(frame,all,sep);
     for(i=1; i&lt;=n; i++)  
	 str = str sprintf("%s", (oddp(i) ? all[i] : fillSlot(all[i],values)))
     return str
 } 
 function fillSlot(str,values) {
     return (str ~ /;/ ? slotsPlugIns(str,values) : values[str])
}
</pre>
<a name="10"></a><h2>Author</h2>
<p>
Tim Menzies
